package com.open.capacity.paper.feign;

import com.open.capacity.common.auth.details.LoginAppUser;
import com.open.capacity.common.constant.ServiceNameConstant;
import com.open.capacity.common.feign.FeignExceptionConfig;
import com.open.capacity.common.model.SysRole;
import com.open.capacity.common.model.SysUser;
import com.open.capacity.common.web.Result;
import com.open.capacity.paper.feign.impl.UserFeignClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Set;

/**
 * @author liangd
 * @since 2021-02-03 17:37
 */
@FeignClient(value = ServiceNameConstant.USER, configuration = FeignExceptionConfig.class, fallbackFactory = UserFeignClientFallback.class, decode404 = true)
public interface UserFeignClient {

    /**
     * 根据用户名查用户
     */
    @GetMapping("/users-anon/login")
    LoginAppUser findByUsername(@RequestParam("username") String username);

    /**
     * 根据用户Id查用户
     */
    @GetMapping("/users/{id}")
    SysUser findUserById(@PathVariable("id") Long id);

    /**
     * 查询单个角色
     */
    @GetMapping("/findById")
    SysRole findById(@RequestParam("id") Long id);

    /**
     * 更新某个用户的称号
     */
    @PutMapping("/title/updateTitleOfRoleCodeByUserId")
    Result updateTitleOfRoleCodeByUserId(@RequestParam("userId") Long userId, @RequestParam("points") Double points, @RequestParam("roleCode")String roleCode);

    /**
     * 根据用户id获取角色
     */
    @GetMapping("/users/{id}/roles")
    Set<SysRole> findRolesByUserId(@PathVariable("id") Long id);
}
